﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Celeriq.Common;

namespace Celeriq.GeneratedTester
{
	internal class DataStore
	{
		public static ChannelFactory<IDataModel> GetFactory()
		{
			var factory = new ChannelFactory<IDataModel>("RepositoryServiceNetTcpBinding");
			return factory;
		}

		public static void AddData(ListingItem item)
		{
			using (var factory = GetFactory())
			{
				var service = factory.CreateChannel();
				AddData(item, service);
			}
		}

		public static void UpdateData(ListingItem item, IDataModel service)
		{
			service.UpdateData(item);
		}

		public static void AddDataList(IEnumerable<ListingItem> list, IDataModel service)
		{
			service.AddDataList(list);
		}

		public static void DeleteData(ListingItem item)
		{
			using (var factory = GetFactory())
			{
				var service = factory.CreateChannel();
				DeleteData(item, service);
			}
		}

		public static void DeleteData(ListingItem item, IDataModel service)
		{
			service.DeleteData(item);
		}

		public static ListingQueryResults QueryData(ListingQuery query)
		{
			using (var factory = GetFactory())
			{
				var service = factory.CreateChannel();
				return QueryData(query, service);
			}
		}

		public static ListingQueryResults QueryData(ListingQuery query, IDataModel service)
		{
			return service.Query(query);
		}

	}
}
